package com.jxmcloud.business.cut.util;


import com.alibaba.fastjson.JSONObject;
import com.jxmcloud.business.ce.model.CeSysParameter;
import com.jxmcloud.business.ce.service.ICeSysParameterService;
import com.jxmcloud.business.cut.constants.CutConstants;
import com.jxmcloud.business.cut.dto.client.LoginNameDto;
import com.jxmcloud.business.cut.feign.xuanle.XuanleClient;
import com.xlcloud.platform.api.config.Constant;
import com.xlcloud.platform.api.exception.BusinessException;
import com.xlcloud.platform.util.PublicUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


/**
 * @author tzw
 */
@Component
public class XuanleRpcUtil {
    @Resource
    private XuanleClient xuanLeClient;
    @Resource
    private ICeSysParameterService ceSysParameterService;

    public LoginNameDto getUserInfoByLoginName(String loginName) {
        String data = xuanLeClient.getUserInfoByLoginName(loginName);
        if (PublicUtil.isEmpty(data)) {
            return null;
        }
        JSONObject body = JSONObject.parseObject(data);
        if (PublicUtil.isEmpty(body.get(Constant.KEY_DATA))) {
            throw new BusinessException("玄乐账号不存在！");
        }
        LoginNameDto dt = body.getObject(Constant.KEY_DATA, LoginNameDto.class);
        if (!MyTool.isTure(dt.getPicPath())) {
            CeSysParameter defaultAvatar = ceSysParameterService.getParamByKeyCache(CutConstants.DEFAULT_AVATAR);
            String defaultPicPath = defaultAvatar.getParameterValue();
            dt.setPicPath(defaultPicPath);
        }
        if (!MyTool.isTure(dt.getNickName())) {
            dt.setNickName(loginName);
        }

        return dt;
    }

}









